<?php
include("backManager/User.php");
if(isset($_POST['submited'])){
	    $id=$_POST['id'];
     	$username=$_POST['username'];
		$pwd=$_POST['pwd'];
		$isSucc=User::updateUser($id,$username,$pwd);
		if($isSucc)
		     header("location:index.php?showMsg=修改管理员成功！");
}
$upId=$_GET["upId"];
$user=User::getUserById($upId);
?>

<script>
var oldname='<?php echo $user->getName() ?>';
function ajax(){
	   var username=$("input[name='username']").val();
	   if(username!=oldname){
	           $.ajax({
			           type: "POST",
			           url: "backManager/usernameAjax.php",
			           data: "username="+username,
			           success: function(msg){
			           if(msg==1){
			                $(".warning").html("用户名已经存在");
			           }else
			                $(".warning").html("用户名可以使用");
			           }
	            });
	   }        
    }
    function claerWaring(){
    	 $(".warning").html("");
    }
    function addFail(){
    	$(".fail").html("修改失败！！");
    }
</script>


<div class="rightTop"><span>修改管理员</span></div><!--rightTop end-->
        <div class="thebody"><!--thebody start-->
        	<div class="bodyInside"><!--bodyInside start-->
                <form action="" method="POST">
       id:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='id' value='<?php echo $user->getId() ?>' readonly/><br />
                用户名：<input type="text" name="username" onchange="ajax();" value='<?php echo $user->getName() ?>'/><span class="warning"></span><br />
                密&nbsp;&nbsp;&nbsp;码：<input type="text" name="pwd" value='<?php echo $user->getPwd() ?>'/><br />
       <input type="submit" name="submited" value="修改确认" border="0" style=" width:70px; height:25px; background:#555555; border:0; color:#ffffff;" />
                </form>
       </div><!--bodyInside end-->
       <div class="rightTop"><span class="fail"></span></div>
</div><!--thebody end-->
<?php
     if(isset($_POST['submited'])){	
		if(!$isSucc)
			 echo "<script>addFail();</script>";
     }
?>